@echo off
chcp 65001 > nul
echo Starting build process...

REM Set variables
set FRONTEND_DIR=web
set BACKEND_DIR=app
set STATIC_DIR=%BACKEND_DIR%\src\main\resources\static

REM Build frontend
echo Building frontend...
cd %FRONTEND_DIR%
call npm install
if errorlevel 1 (
    echo Frontend dependency installation failed
    exit /b 1
)
call npm run build
if errorlevel 1 (
    echo Frontend build failed
    exit /b 1
)
cd ..

REM Clean and copy static resources
echo Cleaning static resource directory...
if exist %STATIC_DIR% rd /s /q %STATIC_DIR%
mkdir %STATIC_DIR%

echo Copying frontend build files...
xcopy /E /I /Y %FRONTEND_DIR%\dist\* %STATIC_DIR%

REM Build backend
echo Building backend...
call mvn clean package -DskipTests

echo Build completed!
pause 